﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace MsForgeReboot.Web.Extensions
{
    using System.Text.RegularExpressions;
    using System.Web.Mvc;

    public static class Html
    {
        public static MvcHtmlString DisplaySummaryFor(this HtmlHelper htmlHelper, string text) {
            return new MvcHtmlString(TakeFirst100Words(ExtractTextFromHtml(text)));
        }

        private static string ExtractTextFromHtml(string htmlText){
            var regex = new Regex("(<.*?>\\s*)+", RegexOptions.Singleline);
            return regex.Replace(htmlText, " ").Trim();
        }

        private static string TakeFirst100Words(string text) {
            return string.Join(" ", text.Split(' ').Take(100));
        }
    }
}